// components/date-picker/index.ts
const app = getApp()
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    maxDate: new Date().getTime(),
    minDate: new Date(2010, 1, 1).getTime(),
    currentDate: new Date().getTime(),
    currentDateText: '',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    toggleDatePicker() {
      // 直接调用组件方法（需获取实例）
      const drawer = this.selectComponent('#v-drawer-date')
      drawer.toggleDrawer()
    },
    onDateConfirm(e) {
      this.toggleDatePicker();

      const selectedDate = e.detail;
      if (!selectedDate || typeof selectedDate !== 'number') return;

      this.setData({
        currentDate: selectedDate,
        currentDateText: app.dateFormatter(selectedDate)
      });

      // 通知父组件
      this.triggerEvent('confirmDate', {
        value: selectedDate,
        formatted: this.data.currentDateText
      });
    }
  }
})